/**
 * @param {number[]} prices
 * @return {number[]}
 */
var finalPrices = function(prices) {
  let result = [];
  for(let i = 0; i < prices.length; i++) {
    for(let j = i + 1; j < prices.length; j++) {
      if(prices[j] <= prices[i]) {
        result.push(prices[i] - prices[j]);
        break;
      }
      if(j == prices.length - 1) {
        result.push(prices[i]);
      }
    }
  }
  result.push(prices[prices.length - 1]);
  return result;
};
let prices = [8,4,6,2,3];
console.log(finalPrices(prices));
prices = [1,2,3,4,5];
console.log(finalPrices(prices));
prices = [10,1,1,6];
console.log(finalPrices(prices));
